#pragma once

#include <string>
#include <pthread.h>
#include <assert.h>

#include <boost/function.hpp>

namespace sevent{

class Thread {
public:
	typedef boost::function <int ()> ThreadFunc;
	explicit Thread(const ThreadFunc & init, const ThreadFunc & run, const ThreadFunc & stop);
	~Thread();
	
	void start();
	int wait();
	int stop();
	bool started() const {
		return _started;
	} 
	pid_t pid() const {
		return _pid;
	} 
	pthread_t tid() const {
		return _tid;
	}

	void setInitRet(int i){
		_initReturn = i; 
	}
private:
	bool _started;
	pid_t _pid;
	pthread_t _tid;
	ThreadFunc _initFunc;
	ThreadFunc _runFunc;
	ThreadFunc _stopFunc;

	int _initReturn;

	static void *startRoutine(void *thread);

	Thread(const Thread & other);
	Thread & operator =(const Thread & other);
};

}
